package com.nine.pesys.model.entity;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * 角色类
 * Created by L先森 on 2014/12/20.
 */
@Entity
@Table(name = "tb_Role")
public class Role implements Serializable{
    private Long id;
    private String name;
    private Set<User> user = new HashSet<User>();
    private Set<USPrivilege> usPrivileges = new HashSet<USPrivilege>();

    @Id
    @Column(name = "id",length = 10)
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, mappedBy = "roles", targetEntity = User.class)
    public Set<User> getUser() {
        return user;
    }

    public void setUser(Set<User> user) {
        this.user = user;
    }

    @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, mappedBy = "roles", targetEntity = USPrivilege.class)
    public Set<USPrivilege> getUsPrivileges() {
        return usPrivileges;
    }

    public void setUsPrivileges(Set<USPrivilege> usPrivileges) {
        this.usPrivileges = usPrivileges;
    }
}
